package org.example.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.Dao.CallbacksDao;
import org.example.Pojo.Callbacks;
import org.example.Service.CallbacksService;
import org.example.Utils.UnionResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.security.auth.callback.Callback;

@Service
public class CallbacksServiceImpl implements CallbacksService {
    @Resource
    CallbacksDao callbacksDao;
    @Override
    public UnionResult addCallback(Callbacks callback) {
        if (callbacksDao.insert(callback) > 0){
            return UnionResult.Success();
        }else{
            return UnionResult.Failure();
        }
    }

    @Override
    public UnionResult removeCallback(Callbacks callback) {
        if (callbacksDao.delete(new QueryWrapper<Callbacks>().eq("uid",callback.getUid()))> 0){
            return UnionResult.Success();
        }else{
            return UnionResult.Failure();
        }
    }

    @Override
    public UnionResult updateCallback(Callbacks callback) {
        if (callbacksDao.updateById(callback) > 0){
            return UnionResult.Success();
        }else{
            return UnionResult.Failure();
        }
    }

    @Override
    public UnionResult getAllCallbacks() {
        return UnionResult.Success("",callbacksDao.selectList(new QueryWrapper<Callbacks>()));
    }

    @Override
    public UnionResult getMyCallbacks(String uid) {
        QueryWrapper<Callbacks> queryWrapper = new QueryWrapper<Callbacks>().eq("userid",uid);
        return UnionResult.Success("",callbacksDao.selectList(queryWrapper));
    }
}
